#include "ref_study.h"
#include <iostream>
#include <cstring>
#include"excpt_study.h"


// 引用绑定函数入口参数
void swap(int &a, int &b)
{
    int temp = a;
    a = b;
    b = temp;
}

// 返回值是引用

int &retRef()
{
    int *p = new int;
    // int *p;

    *p = 5;

    return *p;
}


Array::Array(int length)
{
    this->data = new int[length];
    this->length = length;
}

Array::~Array()
{
    delete data;
    cout << "Array 正在析构" << endl;
}

int &Array::operator[](int index)
{
    if (index >= 0 && index < length)
    {
        return data[index];
    }
    throw ArrayOutOfIndexException("数组越界错误");
}

String::String(const String &other)
{
    cout<<"xx1"<<endl;
    data = new char[strlen(other.data)];
    strcpy(data, other.data);
}

String::String(String &&str)
{
    cout<<"xx2"<<endl;

    data = str.data;
    str.data=nullptr;
}

String::String(char *str)
{
    data = str;
}
String createStr()
{
    return String("test");
}